<template>
  <div class="login-container">
    <el-form class="demo-ruleForm login-page"
             label-position="left"
             label-width="0px">
      <h3 class="title">用户登录</h3>
      <el-form-item>
        <el-input v-model="loginForm.username" placeholder="请输入用户名" type="text" prefix-icon="el-icon-user"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="loginForm.password" placeholder="请输入用户密码" type="password"
                  prefix-icon="el-icon-lock"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" style="width:100%" @click="login" plain>登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import axios from 'axios'

export default {
  name: "Login",
  data() {
    return {
      loginForm: {
        username: '',
        password: ''
      },
      LocationCity: '正在定位',
      success: false,

    }
  },
  methods: {
    login() {
      console.log(this.loginForm.username)
      console.log(this.loginForm.password)
      let _this = this
      axios.post("/myapi/authorize/user/token", {
        username: this.loginForm.username,
        password: this.loginForm.password
      }).then(function (response) {
        console.log(response)
        // console.log(response.data.status)
        if (response.data.accessToken != null) {
          localStorage.setItem('Info', JSON.stringify(response.data))
          console.log(response.data)
          console.log(JSON.stringify(response.data))
          _this.$router.replace({path: "/main"})
        } else {
          _this.$notify.error({
            title: '错误',
            message: "登录凭证错误",
            duration: 0,
          })
        }
      })
    },
  },
  mounted() {
    document.querySelector('body').setAttribute('style', 'background:' +
        'linear-gradient(150deg,#023c43,#056f5e,#115473)'
    );
  }
  ,
  beforeDestroy() {
    document.querySelector('body').removeAttribute('style')
  }
}
</script>

<style>

.login-container {
  width: 100%;
  /*height: 100%;*/
  padding-top: 10%;
}

.login-page {
  -webkit-border-radius: 5px;
  border-radius: 35px;
  margin: 0 auto;
  width: 20%;
  padding: 1.8% 1.5% 1.5%;
  background: #eff;
  border: 1px solid #eaefea;
  box-shadow: 0 0 10px #000;
}

.title {
  margin-top: 10px;
  text-align: center;
}


</style>